#ifndef TABWIN1_H
#define TABWIN1_H

#include <QWidget>
#include <QStandardItemModel>
#include <QTabWidget>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/opencv.hpp>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
#include <QScrollBar>
#include <QTimer>
#include <QMessageBox>
#include <QColorDialog>

namespace Ui {
class TabWin1;
}

class TabWin1 : public QWidget
{
    Q_OBJECT

public:
    explicit TabWin1(QWidget *parent = nullptr);
    ~TabWin1();
    Ui::TabWin1 *getUi(){return ui;};
    void opencv_test();
    void ExportData();
    void contoursMatch(cv::Mat matImage, std::vector<cv::Point> &contourTmp, int a1, int a2, int a3, int b1, int b2, int b3, double scale=100.0f);
    void signContours();
    void init1();
    void init2();
    bool itemToContour(QString &str, std::vector<cv::Point> &coutour);
    cv::Vec3f rgbToHSV(const cv::Vec3b &rgbColor);
    void HSV2RGBButton();
    void showImage(QString wintitle, cv::Mat &mat);
    void setEdgeMethod(int methodTmp){edge_method=methodTmp;opencv_test();};
    void EdgeMethod(cv::InputArray src, cv::OutputArray dst, int method);
    QImage cvMat2QImage(const cv::Mat &mat);
    cv::Mat QImage2cvMat(const QImage &image);

private slots:
    void on_spinBox_valueChanged(int arg1);
    void on_horizontalSlider_valueChanged(int value);
    void on_horizontalSlider_2_valueChanged(int value);
    void on_spinBox_2_valueChanged(int arg1);
    void on_horizontalSlider_3_valueChanged(int value);
    void on_spinBox_3_valueChanged(int arg1);
    void on_horizontalSlider_13_valueChanged(int value);
    void on_spinBox_13_valueChanged(int arg1);
    void on_horizontalSlider_14_valueChanged(int value);
    void on_spinBox_14_valueChanged(int arg1);
    void on_horizontalSlider_15_valueChanged(int value);
    void on_spinBox_15_valueChanged(int arg1);

    void on_horizontalSlider_16_valueChanged(int value);
    void on_tableViewCustomContextMenuRequested(const QPoint &pos);
    void on_tableViewCustomContextMenuRequested2(const QPoint &pos);

    void on_mainEdit_click();
    void ImportData();

    void on_tabWidget_currentChanged(int index);

    void on_pushButton_5_clicked();
    void on_pushButton_4_clicked();


    void on_pushButton_6_clicked();

    void on_pushButton_clicked();

    void on_pushButton_7_clicked();

    void on_groupBox_clicked();

    void on_groupBox_2_clicked();

    void on_pushButton_2_clicked();

public:
    QStandardItemModel *standItemModel, *standItemModel2, *listModel;
private:
    Ui::TabWin1 *ui;
    cv::Mat srcImage;   // 图片
    std::vector<std::vector<cv::Point>> contours;// 保存轮廓
    int contoursSize=-1;
    QTimer *timer;
    QSet<QString> open_cv_windows;              // OpenCV窗口集合
    QTabWidget* mainTabWidget=nullptr;
    int edge_method=0;
    QColorDialog  colorDialog, colorDialog2;
};

#endif // TABWIN1_H
